﻿/**
 * @file status_and_setting.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_watch.h"

#if USE_LV_WATCH_STATUS_AND_SETTING != 0

#include <stdio.h>

/*********************
 *      DEFINES
 *********************/
#define LV_WATCH_LOWER_LIMIT_FOR_BATTERY_4  75
#define LV_WATCH_LOWER_LIMIT_FOR_BATTERY_3  50
#define LV_WATCH_LOWER_LIMIT_FOR_BATTERY_2  25
#define LV_WATCH_LOWER_LIMIT_FOR_BATTERY_1  0

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/
static lv_obj_t * status_content_create(lv_obj_t * par);
static lv_obj_t * setting_content_create(lv_obj_t * par);
static void status_update(lv_anim_t * anim);
static void status_update_anim_start(lv_obj_t * cont);

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
***********************/
lv_obj_t * status_and_setting_create(lv_obj_t * tileview, uint16_t id)
{
    lv_obj_t * tab = launcher_tileview_add_tile(tileview, id);
    LV_ASSERT_MEM(tab);
    if(tab == NULL) return NULL;

    lv_obj_t * status_content = status_content_create(tab);
    lv_obj_align(status_content, tab, LV_ALIGN_IN_TOP_MID, 0, 20);

    lv_obj_t * setting_content = setting_content_create(tab);
    lv_obj_add_style(setting_content, LV_CONT_PART_MAIN, &lv_watch_style_transp);
    lv_obj_align(setting_content, tab, LV_ALIGN_IN_BOTTOM_MID, 0, -20);

    uint8_t flg = 0;
    MMI_Modem_Call_Forward_Info_t * callford_info = NULL;
    for(uint8_t i = 0; i < 4; i++) {
        callford_info = watch_modem_call_forward_query_req((MMI_MODEM_CALL_FORWARD_TYPE)i);
        if(callford_info->CallForwardOn)
        {
            flg = 1;
            break;
        }
    }

    if(flg){
        lv_obj_t * callforward_content = lv_cont_create(tab, status_content);
        lv_obj_set_size(callforward_content, LV_HOR_RES - 32, 30);
        lv_cont_set_layout(callforward_content, LV_LAYOUT_OFF);
        lv_obj_set_base_dir(callforward_content, LV_BIDI_DIR_LTR);
        lv_obj_align(callforward_content, status_content, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
        LV_ASSERT_MEM(callforward_content);
        if(callforward_content == NULL) return NULL;
        lv_obj_t * callforward_label = lv_label_create(callforward_content, NULL);
        lv_obj_add_style(callforward_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
        lv_obj_set_click(callforward_label, false);
        lv_label_set_text_id(callforward_label,WATCH_TEXT_ID_CALLFORD_ENABLED);
        lv_obj_align(callforward_label, callforward_content, LV_ALIGN_CENTER, 0, 0);
        lv_tileview_add_element(tileview, callforward_content);
    }
    lv_tileview_add_element(tileview, status_content);
    lv_tileview_add_element(tileview, setting_content);

    status_update_anim_start(status_content);
    return tab;
}

/**********************
 *   STATIC FUNCTIONS
 **********************/
static void status_update_anim_start(lv_obj_t * cont)
{
    lv_anim_t a;

    lv_anim_init(&a);
    lv_anim_set_var(&a, cont);
    lv_anim_set_time(&a, 1);
    lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
    lv_anim_set_repeat_delay(&a, 1000);       // update every 1s
    lv_anim_set_start_cb(&a, status_update);

    lv_anim_start(&a);
    status_update(&a);
}

static lv_obj_t * cont_create(lv_obj_t * par, lv_align_t cont_layout, lv_style_t * style, lv_coord_t width)
{
    lv_obj_t * content = lv_watch_cont_create(par, cont_layout, style, width);
    lv_obj_set_height(content, 30);
    return content;
}

const char * status_get_battery_img(uint8_t level)
{
    if(level > LV_WATCH_LOWER_LIMIT_FOR_BATTERY_4) {
        return(ICON_STATUS_BATTERY_4);
    }

    if(level > LV_WATCH_LOWER_LIMIT_FOR_BATTERY_3) {
        return(ICON_STATUS_BATTERY_3);
    }

    if(level > LV_WATCH_LOWER_LIMIT_FOR_BATTERY_2) {
        return(ICON_STATUS_BATTERY_2);
    }

    if(level > LV_WATCH_LOWER_LIMIT_FOR_BATTERY_1) {
        return(ICON_STATUS_BATTERY_1);
    }

    return(ICON_STATUS_BATTERY_0);
}

// temp interface for showing, will be delete after hal interface is ready
extern uint8_t get_wifi(void);

static void status_update(lv_anim_t * anim)
{
    lv_obj_t * content = (lv_obj_t *)anim->var;
    lv_obj_t * img;
    char str[20] = {};
    const char * phone_signal_img[] = {ICON_STATUS_SIGNAL_0, ICON_STATUS_SIGNAL_1,
                                       ICON_STATUS_SIGNAL_2, ICON_STATUS_SIGNAL_3,
                                       ICON_STATUS_SIGNAL_4, ICON_STATUS_SIGNAL_4
                                      }; // modem has six level

    lv_status_ext_t * status_ext = (lv_status_ext_t *)lv_obj_get_ext_attr(content);

    // update wifi signal
    bool is_wifi_connected = false;
#if USE_LV_WATCH_STATUS_WIFI || USE_LV_WLAN
    const void * wifi_signal_img[] = {ICON_STATUS_WIFI_0, ICON_STATUS_WIFI_1, ICON_STATUS_WIFI_2,
                                      ICON_STATUS_WIFI_3, ICON_STATUS_WIFI_4
    };

#if USE_LV_WLAN == 0
    lv_img_set_src(status_ext->wifi_signal_img, wifi_signal_img[get_wifi()]);
#else
    HAL_WLAN_SIGNAL_STRENGTH_T act_ap_rssi_level = hal_wlan_get_rssi_level();
    if(HAL_WLAN_SIGNAL_STRENGTH_NO != act_ap_rssi_level) {
        is_wifi_connected = true;
        if(lv_obj_get_hidden(status_ext->wifi_signal_img)) {
            lv_obj_set_hidden(status_ext->wifi_signal_img, false);
        }
        lv_img_set_src(status_ext->wifi_signal_img, wifi_signal_img[act_ap_rssi_level]);
    } else if(false == lv_obj_get_hidden(status_ext->wifi_signal_img)) {
        lv_obj_set_hidden(status_ext->wifi_signal_img, true);
    }
#endif

#endif

    /*update network status and phone signal*/
    lv_obj_clean(status_ext->network_status_cont);
    if(watch_modem_sim_present_check_req() && !setting_is_flying_mode()) {
        MMI_MODEM_PLMN_RAT rat;
        watch_modem_get_operator_req(&rat);

        /* 2G/4G icon */
        lv_obj_t * label = lv_label_create(status_ext->network_status_cont, NULL);
        lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);
        if(MMI_MODEM_PLMN_RAT_LTE == rat) {
            lv_label_set_text(label, "4G");
            lv_img_set_src(status_ext->phone_signal_img, phone_signal_img[watch_modem_get_signal_bar_req()]);
            if(!is_wifi_connected) {
                /* IMS register state */
                uint8_t ims_reg_state = watch_modem_get_ims_reg_state_req();
                if(1 == ims_reg_state) {
                    lv_obj_t * label_ims = lv_label_create(status_ext->network_status_cont, NULL);
                    lv_obj_add_style(label_ims, LV_LABEL_PART_MAIN, &lv_watch_font10);
                    lv_obj_align(label_ims, label, LV_ALIGN_OUT_RIGHT_TOP, 5, 0);
                    lv_label_set_text(label_ims, "HD");
                    lv_obj_set_click(label_ims, false);
                }
            }
        } else if(MMI_MODEM_PLMN_RAT_UMTS == rat) {
            lv_label_set_text(label, "3G");
            lv_img_set_src(status_ext->phone_signal_img, phone_signal_img[watch_modem_get_signal_bar_req()]);
            if(!is_wifi_connected) {
                /* UMTS register state */
                uint8_t umts_reg_state = watch_modem_get_umts_reg_state_req();
                lv_obj_t * label_umts = lv_label_create(status_ext->network_status_cont, NULL);
                lv_obj_add_style(label_umts, LV_LABEL_PART_MAIN, &lv_watch_font10);
                lv_obj_align(label_umts, label, LV_ALIGN_OUT_RIGHT_TOP, 5, 0);
                if(0 == umts_reg_state) {
                    lv_label_set_text(label_umts, "W");
                } else if(1 == umts_reg_state) {
                    lv_label_set_text(label_umts, "TD");
                } else if(2 == umts_reg_state){
                    lv_label_set_text(label_umts, "H");
                }
            }
        } else if(MMI_MODEM_PLMN_RAT_GSM == rat) {
            lv_label_set_text(label, "2G");
            lv_img_set_src(status_ext->phone_signal_img, phone_signal_img[watch_modem_get_signal_bar_req()]);
            if(!is_wifi_connected) {
                /* GSM register state */
                uint8_t gsm_reg_state = watch_modem_get_gsm_reg_state_req();
                if(1 == gsm_reg_state) {
                    lv_obj_t * label_gsm = lv_label_create(status_ext->network_status_cont, NULL);
                    lv_obj_add_style(label_gsm, LV_LABEL_PART_MAIN, &lv_watch_font10);
                    lv_obj_align(label_gsm, label, LV_ALIGN_OUT_RIGHT_TOP, 5, 0);
                    lv_label_set_text(label_gsm, "E");
                    lv_obj_set_click(label_gsm, false);
                }
            }
        } else {
            lv_label_set_text(label, "");
            lv_img_set_src(status_ext->phone_signal_img, phone_signal_img[0]);
        }

        lv_obj_set_click(label, false);
    } else if(setting_is_flying_mode()) {
        lv_img_set_src(status_ext->phone_signal_img, ICON_FLYING_MODE);
    } else {
        img = lv_img_create(status_ext->network_status_cont, NULL);
        LV_ASSERT_MEM(img);
        if(img == NULL) return;
        lv_img_set_src(img, ICON_STATUS_NO_SIM_CARD);
        lv_img_set_src(status_ext->phone_signal_img, phone_signal_img[0]);
    }

    // update charging status
    if(HAL_CHG_CONNECTED == Hal_Charger_Get_Status()) {
        if(NULL == status_ext->charging_img) {
            status_ext->charging_img = lv_img_create(lv_obj_get_parent(status_ext->battery_img), NULL);
            LV_ASSERT_MEM(status_ext->charging_img);
            if(status_ext->charging_img == NULL) return;
            lv_img_set_src(status_ext->charging_img, ICON_STATUS_IN_CHARGING);
            lv_obj_align(status_ext->charging_img, status_ext->battery_img, LV_ALIGN_OUT_LEFT_MID, 0, 0);
        }
    } else {
        if(NULL != status_ext->charging_img) {
            lv_obj_del(status_ext->charging_img);
        }
        status_ext->charging_img = NULL;
    }

    // update battery status
    lv_img_set_src(status_ext->battery_img, status_get_battery_img(Hal_Battery_Get_Status()));
    lv_obj_t * battery_label = lv_obj_get_child(status_ext->battery_img, NULL);

#if USE_LV_WATCH_STATUS_BATT_VALUE
    lv_obj_add_style(battery_label, LV_LABEL_PART_MAIN, &lv_watch_font14);
    snprintf(str, 20, "%d", Hal_Battery_Get_Status());
    lv_label_set_text(battery_label, str);
    lv_obj_align(battery_label, NULL, LV_ALIGN_CENTER, 0, 0);
#endif

    if(HAL_CHG_CONNECTED == Hal_Charger_Get_Status()) {
        if(Hal_Battery_Get_Status() == 100) {
            lv_obj_add_style(battery_label, LV_LABEL_PART_MAIN, &lv_watch_font10);
            lv_label_set_text(battery_label, "OK");
            lv_obj_align(battery_label, NULL, LV_ALIGN_CENTER, 0, 0);
        }
    }

    // update time
    hal_rtc_t tm;
    const uint16_t week_text_id[] = {WATCH_TEXT_ID_SUNDAY,
                                     WATCH_TEXT_ID_MONDAY,
                                     WATCH_TEXT_ID_TUESDAY,
                                     WATCH_TEXT_ID_WEDNESDAY,
                                     WATCH_TEXT_ID_THURSDAY,
                                     WATCH_TEXT_ID_FRIDAY,
                                     WATCH_TEXT_ID_SATURDAY
                                    };

    Hal_Rtc_Gettime(&tm);

    if(LANG_EN == lv_lang_act()) {
        snprintf(str, 20, "%.2d-%.2d", tm.tm_mon, tm.tm_mday);
    }
    #if USE_LV_WATCH_LANG_ARABIC != 0
    else if(LANG_AR == lv_lang_act()) {
        snprintf(str, 20, "%.2d/%.2d", tm.tm_mday, tm.tm_mon);
    }
    #endif
    else {
        snprintf(str, 20, "%.2d%s%.2d%s", tm.tm_mon, (char *)lv_lang_get_text(WATCH_TEXT_ID_MONTH), tm.tm_mday, (char *)lv_lang_get_text(WATCH_TEXT_ID_DATE));
    }
    lv_label_set_text(status_ext->date_label, str);
    lv_cont_set_fit(lv_obj_get_parent(status_ext->date_label), LV_FIT_TIGHT);
    lv_obj_align(lv_obj_get_parent(status_ext->date_label), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 10, -8);

    lv_label_set_text_id(status_ext->weekday_label, week_text_id[tm.tm_wday]);
    lv_cont_set_fit(lv_obj_get_parent(status_ext->weekday_label), LV_FIT_TIGHT);
    lv_obj_align(lv_obj_get_parent(status_ext->weekday_label), NULL, LV_ALIGN_IN_BOTTOM_MID, 10, -8);

    snprintf(str, 20, "%.2d:%.2d", tm.tm_hour, tm.tm_min);
    lv_label_set_text(status_ext->time_label, str);
    lv_cont_set_fit(lv_obj_get_parent(status_ext->time_label), LV_FIT_TIGHT);
    lv_obj_align(lv_obj_get_parent(status_ext->time_label), NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -5, -8);
    lv_label_set_align(status_ext->time_label, LV_ALIGN_IN_TOP_RIGHT);
}

static lv_obj_t * status_content_create(lv_obj_t * par)
{
    if(!par) par = lv_scr_act();
    lv_coord_t width = LV_HOR_RES - 50;

    lv_obj_t * content = lv_cont_create(par, NULL);
    lv_obj_add_style(content, LV_CONT_PART_MAIN, &lv_watch_cont_opa1);
    lv_obj_set_size(content, LV_HOR_RES - 32, 77);
    lv_cont_set_layout(content, LV_LAYOUT_OFF);
    lv_obj_set_base_dir(content, LV_BIDI_DIR_LTR);
    LV_ASSERT_MEM(content);
    if(content == NULL) return NULL;

    lv_obj_set_click(content, false);
    lv_status_ext_t * status_ext = (lv_status_ext_t *)lv_obj_allocate_ext_attr(content, sizeof(lv_status_ext_t));

    lv_obj_t * content_row0 = cont_create(content, LV_LAYOUT_ROW_MID, &lv_watch_style_transp, width);
    lv_obj_align(content_row0, content, LV_ALIGN_IN_TOP_MID, 0, 6);

    lv_obj_t * content_1 = cont_create(content_row0, LV_LAYOUT_ROW_MID, &lv_watch_style_transp, width / 3);
    /*signal*/
    status_ext->phone_signal_img = lv_img_create(content_1, NULL);
    LV_ASSERT_MEM(status_ext->phone_signal_img);
    if(status_ext->phone_signal_img == NULL) return NULL;

    /*wifi*/
#if USE_LV_WATCH_STATUS_WIFI || USE_LV_WLAN
    status_ext->wifi_signal_img = lv_img_create(content_1, NULL);
    LV_ASSERT_MEM(status_ext->wifi_signal_img);
    if(status_ext->wifi_signal_img == NULL) return NULL;
#endif

    /*network status content*/
    status_ext->network_status_cont = cont_create(content_row0, LV_LAYOUT_OFF, &lv_watch_style_transp, width / 3 - 10);

    /*battery content*/
    lv_obj_t * content_2 = cont_create(content_row0, LV_LAYOUT_OFF, &lv_watch_style_transp, width / 3);

    /*battery status*/
    status_ext->battery_img = lv_img_create(content_2, NULL);
    LV_ASSERT_MEM(status_ext->battery_img);
    if(status_ext->battery_img == NULL) return NULL;
    lv_img_set_src(status_ext->battery_img, status_get_battery_img(Hal_Battery_Get_Status()));
    lv_obj_align(status_ext->battery_img, content_2, LV_ALIGN_IN_RIGHT_MID, -8, 0);

    lv_obj_t * battery_label = lv_label_create(status_ext->battery_img, NULL);
    lv_label_set_text(battery_label, "");

#if USE_LV_WATCH_STATUS_BATT_VALUE
    /*battery level*/
    char str[20] = {};

    lv_obj_add_style(battery_label, LV_LABEL_PART_MAIN, &lv_watch_font14);
    snprintf(str, 20, "%d", Hal_Battery_Get_Status());
    lv_label_set_text(battery_label, str);
    lv_obj_set_click(battery_label, false);
    lv_obj_align(battery_label, NULL, LV_ALIGN_CENTER, 0, 0);
#endif

    // charging status
    status_ext->charging_img = NULL;
    if(HAL_CHG_CONNECTED == Hal_Charger_Get_Status()) {
        if(Hal_Battery_Get_Status() == 100) {
            lv_obj_add_style(battery_label, LV_LABEL_PART_MAIN, &lv_watch_font10);
            lv_label_set_text(battery_label, "OK");
            lv_obj_set_click(battery_label, false);
            lv_obj_align(battery_label, NULL, LV_ALIGN_CENTER, 0, 0);
        }

        status_ext->charging_img = lv_img_create(content_2, NULL);
        LV_ASSERT_MEM(status_ext->charging_img);
        if(status_ext->charging_img == NULL) return NULL;
        lv_img_set_src(status_ext->charging_img,  ICON_STATUS_IN_CHARGING);
        lv_obj_align(status_ext->charging_img, status_ext->battery_img, LV_ALIGN_OUT_LEFT_MID, 0, 0);
    }

    lv_obj_t * content_4 = cont_create(content, LV_LAYOUT_OFF, &lv_watch_style_transp, width);
    /*date*/
    status_ext->date_label = lv_label_create(content_4, NULL);
    lv_obj_add_style(status_ext->date_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_set_click(status_ext->date_label, false);

    lv_obj_t * content_5 = cont_create(content, LV_LAYOUT_OFF, &lv_watch_style_transp, width);
    /*week*/
    status_ext->weekday_label = lv_label_create(content_5, status_ext->date_label);
    lv_obj_set_click(status_ext->weekday_label, false);

    lv_obj_t * content_6 = cont_create(content, LV_LAYOUT_OFF, &lv_watch_style_transp, width);
    /*time*/
    status_ext->time_label = lv_label_create(content_6, status_ext->date_label);
    lv_obj_set_click(status_ext->time_label, false);

    return content;
}

static void brightness_slider_action(lv_obj_t * slider, lv_event_t event)
{
    if(LV_EVENT_VALUE_CHANGED == event) {
        int16_t brightness = lv_slider_get_value(slider);
        setting_set_backlight_intensity(brightness, false);
    }
}

static void volume_slider_action(lv_obj_t * slider, lv_event_t event)
{
    if(lv_slider_is_dragged(slider)) return;

    uint16_t volume = lv_slider_get_value(slider);

    setting_set_ring_volume((uint8_t)volume, false, true);
}
static void send_pressed_to_tileview(lv_obj_t * obj)
{
    lv_obj_t * tileview_scrl = lv_obj_get_parent(lv_obj_get_parent(lv_obj_get_parent(obj)));
    lv_signal_send(tileview_scrl, LV_SIGNAL_PRESSED, NULL);
}

static void brightness_btn_action(lv_obj_t * obj, lv_event_t event)
{
    if(LV_EVENT_CLICKED == event) {
        slider_create(NULL, SETTING_BRIGHTNESS, 130, brightness_slider_action);
    }
    if(LV_EVENT_PRESSED == event) {
        send_pressed_to_tileview(obj);
    }
}

static void volume_btn_action(lv_obj_t * obj, lv_event_t event)
{
    if(LV_EVENT_CLICKED == event) {
        slider_create(NULL, SETTING_VOLUME, 130, volume_slider_action);
    }
    if(LV_EVENT_PRESSED == event) {
        send_pressed_to_tileview(obj);
    }
}

static void setting_btn_action(lv_obj_t * obj, lv_event_t event)
{
    if(LV_EVENT_CLICKED == event) {
        setting_create_event_cb(obj, event);
    }
    if(LV_EVENT_PRESSED == event) {
        send_pressed_to_tileview(obj);
    }
}

static lv_obj_t * setting_content_create(lv_obj_t * par)
{
    if(!par) par = lv_scr_act();

    lv_obj_t * content = lv_cont_create(par, NULL);
    LV_ASSERT_MEM(content);
    if(content == NULL) return NULL;
    lv_cont_set_fit(content, LV_FIT_TIGHT);
    lv_cont_set_layout(content, LV_LAYOUT_ROW_MID);
    lv_tileview_add_element(lv_obj_get_parent(par), content);

    lv_obj_t * btn;
    btn = lv_imgbtn_create(content, NULL);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_RELEASED, ICON_STATUS_BRIGHTNESS);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_PRESSED, ICON_STATUS_BRIGHTNESS);
    lv_obj_set_event_cb(btn, brightness_btn_action);
    lv_tileview_add_element(lv_obj_get_parent(par), btn);

    btn = lv_imgbtn_create(content, NULL);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_RELEASED, ICON_STATUS_VOLUME);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_PRESSED, ICON_STATUS_VOLUME);
    lv_obj_set_event_cb(btn, volume_btn_action);
    lv_tileview_add_element(lv_obj_get_parent(par), btn);

    btn = lv_imgbtn_create(content, NULL);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_RELEASED, ICON_STATUS_SETTING);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_PRESSED, ICON_STATUS_SETTING);
    lv_obj_set_event_cb(btn, setting_btn_action);
    lv_tileview_add_element(lv_obj_get_parent(par), btn);

    return content;
}

static void ims_vops_not_support_destory(lv_obj_t * activity_obj)
{
    lv_watch_png_cache_all_free();
}

static void not_support_ok_btn_action(lv_obj_t * btn, lv_event_t event)
{
    (void)btn;
    if(LV_EVENT_CLICKED == event) {
        lv_watch_png_cache_all_free();
        lv_obj_del(lv_watch_get_activity_obj(ACT_ID_IMS_VOPS));
    }
}

static void ok_btn_action(lv_obj_t * btn, lv_event_t event)
{
    (void)btn;
    if(LV_EVENT_CLICKED == event) {
        lv_watch_png_cache_all_free();
        lv_obj_del(lv_watch_get_activity_obj(ACT_ID_IMS_VOPS_SMS));
        watch_modem_open_volte();
    }
}

static void cancel_btn_action(lv_obj_t * btn, lv_event_t event)
{
    (void)btn;
    if(LV_EVENT_CLICKED == event) {
        lv_watch_png_cache_all_free();
        lv_obj_del(lv_watch_get_activity_obj(ACT_ID_IMS_VOPS_SMS));
    }
}

static lv_obj_t * ims_vops_send_sms_create(lv_obj_t * activity_obj)
{
    if(NULL == activity_obj) {
        lv_watch_activity_ext_t activity_ext;
        memset(&activity_ext, 0, sizeof(lv_watch_activity_ext_t));
        activity_ext.actId = ACT_ID_IMS_VOPS_SMS;
        activity_ext.create = ims_vops_send_sms_create;
        activity_ext.prepare_destory = ims_vops_not_support_destory;
        activity_obj = lv_watch_creat_activity_obj(&activity_ext);
        LV_ASSERT_MEM(activity_obj);
        if(NULL == activity_obj) {
            return NULL;
        }
    }

    lv_obj_t * obj = lv_watch_obj_create(activity_obj);
    LV_ASSERT_MEM(obj);
    if(obj == NULL) return NULL;
    lv_watch_obj_set_anim_mode(obj, LV_WATCH_ANIM_HOR_RIGHT_HIDE);

    lv_obj_t * label = lv_label_create(obj, NULL);
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);

    lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
    lv_obj_set_size(label, 200, 45);
    lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
    lv_obj_set_click(label, false);
    lv_label_set_text_id(label, WATCH_TEXT_ID_IMSVOPS_SMS);

    lv_obj_align(label, obj, LV_ALIGN_CENTER, 0, 0);

    lv_obj_t * ok_btn = lv_btn_create(obj, NULL);
    lv_obj_set_click(ok_btn, true);
    lv_obj_set_size(ok_btn, LV_HOR_RES / 4, LV_VER_RES / 4);
    lv_obj_t * btnlabel = lv_label_create(ok_btn, NULL);
    lv_obj_add_style(btnlabel, LV_LABEL_PART_MAIN, &lv_watch_font20);

    lv_label_set_text_id(btnlabel, WATCH_TEXT_ID_OK);
    lv_obj_add_style(ok_btn, LV_BTN_PART_MAIN, &lv_watch_cont_opa2);
    lv_obj_align(ok_btn, obj, LV_ALIGN_IN_BOTTOM_LEFT, 20, -10);
    lv_obj_set_event_cb(ok_btn, ok_btn_action);

    lv_obj_t * cancel_btn = lv_btn_create(obj, NULL);
    lv_obj_set_click(cancel_btn, true);
    lv_obj_set_size(cancel_btn, LV_HOR_RES / 4, LV_VER_RES / 4);
    btnlabel = lv_label_create(cancel_btn, NULL);
    lv_obj_add_style(btnlabel, LV_LABEL_PART_MAIN, &lv_watch_font20);

    lv_label_set_text_id(btnlabel, WATCH_TEXT_ID_CANCEL);
    lv_obj_add_style(cancel_btn, LV_BTN_PART_MAIN, &lv_watch_cont_opa2);
    lv_obj_align(cancel_btn, obj, LV_ALIGN_IN_BOTTOM_RIGHT, -20, -10);
    lv_obj_set_event_cb(cancel_btn, cancel_btn_action);

    return obj;
}

static lv_obj_t * ims_vops_not_support_create(lv_obj_t * activity_obj)
{
    if(NULL == activity_obj) {
        lv_watch_activity_ext_t activity_ext;
        memset(&activity_ext, 0, sizeof(lv_watch_activity_ext_t));
        activity_ext.actId = ACT_ID_IMS_VOPS;
        activity_ext.create = ims_vops_not_support_create;
        activity_ext.prepare_destory = ims_vops_not_support_destory;
        activity_obj = lv_watch_creat_activity_obj(&activity_ext);
        LV_ASSERT_MEM(activity_obj);
        if(NULL == activity_obj) {
            return NULL;
        }
    }

    lv_obj_t * obj = lv_watch_obj_create(activity_obj);
    LV_ASSERT_MEM(obj);
    if(obj == NULL) return NULL;
    lv_watch_obj_set_anim_mode(obj, LV_WATCH_ANIM_HOR_RIGHT_HIDE);

    lv_obj_t * label = lv_label_create(obj, NULL);
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);

    lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
    lv_obj_set_size(label, 200, 45);
    lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
    lv_obj_set_click(label, false);
    lv_label_set_text_id(label, WATCH_TEXT_ID_IMSVOPS);

    lv_obj_align(label, obj, LV_ALIGN_CENTER, 0, 0);

    lv_obj_t * ok_btn = lv_btn_create(obj, NULL);
    lv_obj_set_click(ok_btn, true);
    lv_obj_set_size(ok_btn, LV_HOR_RES / 5, LV_VER_RES / 5);
    lv_obj_t * btnlabel = lv_label_create(ok_btn, NULL);
    lv_obj_add_style(btnlabel, LV_LABEL_PART_MAIN, &lv_watch_font20);

    lv_label_set_text_id(btnlabel, WATCH_TEXT_ID_OK);
    lv_obj_add_style(ok_btn, LV_BTN_PART_MAIN, &lv_watch_cont_opa2);
    lv_obj_align(ok_btn, obj, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
    lv_obj_set_event_cb(ok_btn, not_support_ok_btn_action);

    return obj;
}

void watch_modem_ims_vops_ind(uint8_t display_sendsms_flg)
{
    if(true == watch_modem_sim_present_check_req()) {
        if(display_sendsms_flg) {
            ims_vops_send_sms_create(NULL);
        } else {
            ims_vops_not_support_create(NULL);
        }
    }
}

#endif /*USE_LV_WATCH_STATUS_AND_SETTING*/
